Skip to content

Enhanced MV3 Reliability Fixes#314

Open
jeny-feldman wants to merge 1 commit intotshaddix:masterfrom
GetEvinced:jeny/bug/mv3-realoability-fixes
Open

Enhanced MV3 Reliability Fixes#314
jeny-feldman wants to merge 1 commit intotshaddix:masterfrom
GetEvinced:jeny/bug/mv3-realoability-fixes

Conversation

@jeny-feldman
Copy link
Copy Markdown

This PR handles critical reliability issues when using webext-redux with Manifest V3 service workers, building on the improvements from v4.0.0.

Problems Solved

  1. State Initialization Failures When Service Worker Wakes Up

Problem: When a dormant service worker is awakened by a message, sendResponse() doesn't work reliably in Chrome's MV3 implementation. This caused proxy stores (in content scripts, popups, etc.) to fail during initialization when they tried to fetch the initial state from the background store.

Solution: Modified the state provider listener in wrapStore.js to use a dual-response approach:
Primary method: Broadcast the full state using browser.runtime.sendMessage() (reliable in MV3)
Fallback method: Still call sendResponse() for compatibility with smaller states
The proxy store's initialization logic already handles both message types, so it will use whichever arrives first and ignore duplicates.

  1. Race Condition with Patch Messages During Initialization

Problem: If state patches (PATCH_STATE_TYPE messages) arrived before the initial full state (STATE_TYPE or FETCH_STATE_TYPE), they would be applied to an empty state object. This resulted in broken/partial state in proxy stores, causing UI bugs and undefined behavior.
Solution: Added a guard in Store.js to only apply patches after the store has received the full initial state at least once (tracked by the readyResolved flag that's already used for the ready() promise).

Testing
Screenshot 2026-02-11 at 13 42 57

Impact

  • Proxy stores now reliably initialize even when waking dormant service workers
  • Eliminates race conditions during initialization
  • No breaking changes to the API
  • Backwards compatible with existing implementations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant